	//application icon
	import flash.events.Event;
	
	import model.CompanyProfileModel;
	
	
	//states constants
	public var STATE_LOGIN:String = 'LOGIN';
	public var STATE_USER_MANAGEMENT:String = 'USER_MANAGEMENT';
	public var STATE_MAIN:String = 'MAIN';
	public var STATE_USER_PROFILE:String = 'USER_PROFILE';
	
	//xml filenames constants
	public var FILENAME_USERS_XML:String = 'users.xml';
	
	//constant for session
	public var LOGGED_USER_ID:String = '';
	public var LOGGED_PASSWORD:String = '';
	[Bindable] public var IS_ADMIN:Boolean;
	
	//master constants
	import nrb.utils.XMLHelper;
	import mx.controls.LinkButton;
	import flash.data.SQLConnection;
	import flash.data.SQLMode;
	import flash.filesystem.File;
	import mx.controls.Alert;
	import flash.data.SQLStatement;
	import flash.data.SQLResult;
	import flash.events.SQLEvent;
	import model.Product;
	import model.Products;
	import model.Suppliers;
	public var STR_PATH_UOM_XML:String = "uom_mstr.xml";
	public var STR_PATH_SUPPLIERS_XML:String = "suppliers_mstr.xml";
	public var STR_URL_XML_PRODUCTS:String = "product_mstr.xml";
	public var STR_URL_XML_SUPPLIERPRODUCTS:String = "supplierproduct_mstr.xml";
	public var STR_PATH_CATEGORIES_XML:String = "category_mstr.xml";
	public var STR_PATH_ADJUSTMENTS_XML:String = "adjustments.xml";
	public var FILENAME_COMPANY_PROFILE_XML:String = 'CompanyProfile.xml';
	public var xml_uom:XML;
	public var nxml:XMLHelper = new XMLHelper();
	public var COMPANY_PROFILE:CompanyProfileModel;
	public static var suppliers:Suppliers;
	
	private const CONST_VW_PRODUCT:Number = 1;
	private const CONST_VW_CATEGORY:Number = 3;
	
	public var cust_usermanagement:LinkButton;
	
	//Create a new in-memory database and a synchronous connection.
	
	
	public function func_init(): void {
		//connection has been established and can be used for other database operations at this point.
		this.COMPANY_PROFILE = new CompanyProfileModel();
		func_change_state(STATE_LOGIN);
		
		suppliers = new Suppliers();
		
		func_init_uom();
		func_init_companyprofile();
	}
	
	
	
	public function func_init_uom(): void {
		var xml_parentnode:XML = XML("<uoms></uoms>");
		xml_parentnode.appendChild(XML("<uom>Piece</uom>"));
		xml_parentnode.appendChild(XML("<uom>Pack</uom>"));
		xml_parentnode.appendChild(XML("<uom>Dozen</uom>"));
		var str_xml:String =  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+xml_parentnode.toXMLString();
		
		if (!nxml.func_check_fileexists(STR_PATH_UOM_XML)) nxml.func_create_xml(xml_parentnode, STR_PATH_UOM_XML);
		xml_uom = nxml.func_get_xml();
	}
	
	public function func_state_change_handler(evt:Event):void {
		
	}
	
	public function func_change_state(state:String): void {
		this.currentState = state;
		
		if(state == STATE_LOGIN)
			login.func_init();
		else if(state == STATE_USER_MANAGEMENT)
			user_management.func_init();
		else if(state == STATE_USER_PROFILE)
			user_profile.func_init();
		else if(state == STATE_MAIN) {
			if (this.cust_usermanagement)
			this.cust_usermanagement.visible = this.IS_ADMIN;
		}
	}
	
	public function func_refresh():void {
		if(this.currentState == this.STATE_MAIN)
		if (this.main.vs_ndx.selectedIndex == this.CONST_VW_PRODUCT)
		this.main.vw_product_search.func_refresh();
		else if (this.main.vs_ndx.selectedIndex == this.CONST_VW_CATEGORY)
		this.main.vw_categories.func_refresh();
	}
	//checks if company profile xml exists and creates it if it doesn't
	public function func_init_companyprofile(): void {
		var xml_parentnode:XML = XML("<company_profile />");
		var str_xml:String =  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+xml_parentnode.toXMLString();
		
		if (!nxml.func_check_fileexists(FILENAME_COMPANY_PROFILE_XML)) nxml.func_create_xml(xml_parentnode, FILENAME_COMPANY_PROFILE_XML);
		else {
			nxml.func_open_xml(FILENAME_COMPANY_PROFILE_XML);
			this.COMPANY_PROFILE.func_set_attributes(nxml.func_get_xml());
		}
	}
	
	